//
//  TJMainViewController.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/13.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJMainViewController.h"
#import "TJHomeViewController.h"
#import "TJMessageViewController.h"
#import "TJDiscoverViewController.h"
#import "TJProfileViewController.h"
#import "TJTabBar.h"

@interface TJMainViewController ()

@end

@implementation TJMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 1,添加四个子控制器.
    [self addChildVC];
    
    // 2,自定义tabar.
//    self.tabBar = [[TJTabBar alloc] init]; //readonly要用KVC赋值.
    [self setValue:[[TJTabBar alloc] init] forKeyPath:@"tabBar"];
    
}

- (void)addChildVC{

    // 首页
    [self initchildVC:[[TJHomeViewController alloc] init] title:@"首页" img:@"tabbar_home" selectedImg:@"tabbar_home_selected"];
    
    // 消息
    [self initchildVC:[[TJMessageViewController alloc] init] title:@"消息" img:@"tabbar_message_center" selectedImg:@"tabbar_message_center_selected"];
    
    // 发现
    [self initchildVC:[[TJDiscoverViewController alloc] init] title:@"发现" img:@"tabbar_discover" selectedImg:@"tabbar_discover_selected"];
    
    // 我
    [self initchildVC:[[TJProfileViewController alloc] init] title:@"我" img:@"tabbar_profile" selectedImg:@"tabbar_profile_selected"];
}

- (void)initchildVC:(UIViewController*)childVC title:(NSString *)title img:(NSString *)imgName selectedImg:(NSString *)selectedImgName {

    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:childVC];
    childVC.title = title;
    childVC.tabBarItem.image = [UIImage imageNamed:imgName];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置tabBar的字体颜色.
    [childVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateNormal];
    [self addChildViewController:navVC];
    
}


@end
